//
//  DPWalletAccoutViewController.swift
//  DoctorEPlus
//
//  Created by 王林波 on 2021/3/19.
//

import UIKit
import IDealist

class DPWalletAccoutViewController: BHBaseViewController {

    lazy var tableView: UITableView = {
        let view = UITableView.buildTableView(style: .plain)
        view.frame = CGRect(x: 0, y: UIScreen.begainY, width: UIScreen.width, height: UIScreen.showHeight)
        view.register(UINib.init(nibName: "DPWalletAccountInfoCell", bundle: nil), forCellReuseIdentifier: "DPWalletAccountInfoCell")
        view.delegate = self
        view.dataSource = self
        return view
    }()
    
    
    var alipayAccountModel = DPWalletAlipayInfoModel.init()
    
    override func viewDidLoad() {
        super.viewDidLoad()

        self.bh_navigationBar.title_label.text = "账户"
        
        self.view.addSubview(self.tableView)
        
    }
   

}

extension DPWalletAccoutViewController: UITableViewDelegate,UITableViewDataSource {
    func numberOfSections(in tableView: UITableView) -> Int {
        return 1
    }
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return 1
    }
    func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        return 60
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: "DPWalletAccountInfoCell", for: indexPath) as! DPWalletAccountInfoCell
        cell.model = self.alipayAccountModel
        cell.unbindActBlock = { [weak self] in
            BHCommonTool.showCustomAlertWith(showVC: nil, title: "提示", message: "是否确定解除支付宝绑定？", okBtn: "再想想", cancel: "现在解除") { (cancel) in
                if cancel == false {
                    self?.unbindAccountService()
                }
            }
        }
        
        return cell
    }
}

extension DPWalletAccoutViewController {
  
    
    func unbindAccountService() {
        let manager = BHHTTPClient.init()
        manager.post(url: String.wallet_alipay_unBind_url, paramters: [:]) { (success, errorMsg, responseDic) in
            if success == true {
                BHToast.toast(text: "解绑成功")
                DispatchQueue.main.asyncAfter(deadline: .now()+1.5) {
                    self.navigationController?.popViewController(animated: true)
                }
            }else {
                BHToast.toast(text: errorMsg)
            }
        }
    }
 
}
 
